<template>
    <div class="auth-bg">
      <div class="auth-card">
        <div class="auth-logo">
          <el-icon :size="48" color="#409EFF"><Platform /></el-icon>
          <h1>重置密码</h1>
          <p class="subtitle">请填写验证码和新密码</p>
        </div>
  
        <el-form :model="form" @submit.prevent="handleReset" class="auth-form">
          <el-form-item>
            <el-input
              v-model="form.code"
              prefix-icon="Key"
              placeholder="6 位验证码"
              size="large"
              maxlength="6"
            />
          </el-form-item>
  
          <el-form-item>
            <el-input
              v-model="form.newPassword"
              prefix-icon="Lock"
              type="password"
              placeholder="请输入新密码"
              size="large"
              show-password
            />
          </el-form-item>
  
          <el-button
            type="primary"
            size="large"
            native-type="submit"
            :loading="loading"
            style="width: 100%"
          >
            确认重置
          </el-button>
  
          <div class="auth-footer">
            <el-link type="primary" @click="$router.push('/login')">
              返回登录
            </el-link>
          </div>
        </el-form>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ref, onMounted } from 'vue'
  import { ElMessage } from 'element-plus'
  import { useRouter, useRoute } from 'vue-router'
  import request from '@/api/index'
  const route = useRoute()
  const router = useRouter()
  
  const form = ref({ email: '', code: '', newPassword: '' })
  const loading = ref(false)
  
  onMounted(() => {
    form.value.email = route.query.email || ''
    if (!form.value.email) router.replace('/forgot')
  })
  
  const handleReset = async () => {
  if (!form.value.code || !form.value.newPassword) {
    return ElMessage.warning('请填写完整')
  }
  loading.value = true
  try {
    await request.post('/auth/reset', {
      email: form.value.email,
      code: form.value.code,
      newPassword: form.value.newPassword
    })
    ElMessage.success('密码重置成功')
    router.push('/login')
  } catch (e) {
    ElMessage.error(e?.response?.data?.message || '重置失败')
  } finally {
    loading.value = false
  }
}
  </script>
 <style scoped>
 .auth-bg {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 40px 32px;
  background: rgba(255, 255, 255, 0.88);
  border-radius: 20px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(12px);
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0);   }
}

.auth-logo {
  text-align: center;
  margin-bottom: 30px;
}

.auth-logo h1 {
  margin: 8px 0 4px;
  font-size: 26px;
  color: #333;
}

.subtitle {
  font-size: 14px;
  color: #666;
  margin: 0;
}

.auth-form .el-button {
  height: 46px;
  border-radius: 8px;
  font-size: 16px;
}

.auth-footer {
  margin-top: 20px;
  text-align: center;
}

@media (max-width: 480px) {
  .auth-card {
    margin: 0 10px;
    padding: 30px 20px;
  }
}
 </style> 